
use common
go
if exists (select 1 from sysobjects where name = "p_PopulateChildCust")
begin
        drop proc p_PopulateChildCust
    	IF OBJECT_ID('dbo.p_PopulateChildCust') IS NOT NULL
        	PRINT '<<< FAILED DROPPING PROCEDURE dbo.p_PopulateChildCust >>>'
    	ELSE
        	PRINT '<<< DROPPED PROCEDURE dbo.p_PopulateChildCust >>>'
end
go
create proc p_PopulateChildCust 
( @Parent	integer 
) 
as 
begin 
  select a.CuId 
  ,      a.ObjName 
  ,      a.Scope 
  from   common..t_ReleaseObjects	a 
  where  a.Parent     = @Parent 
  and    a.CuId      != a.Parent 
  
 
  UNION  
  select a.CuId 
  ,      a.ObjName 
  ,      a.Scope 
  from   common..t_ReleaseObjects	  a 
  where a.Status = 'O'  
  and   a.Parent = @Parent 
  and   a.Parent = a.CuId   
  and   a.Scope  in ('X','I','F') 
end 
return 0 
go
grant execute on p_PopulateChildCust to public
go
IF OBJECT_ID('dbo.p_PopulateChildCust') IS NOT NULL
    PRINT '<<< CREATED PROCEDURE dbo.p_PopulateChildCust >>>'
ELSE
    PRINT '<<< FAILED CREATING PROCEDURE dbo.p_PopulateChildCust >>>'
go